/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        qb_modules.h
// Purpose:     
// Author:      syy
// Modified by: 
// Created:     2014/5/13 19:59
// RCS-ID:      
// Licence:     
/////////////////////////////////////////////////////////////////////////////
#ifndef _PR_MODULES_H_
#define _PR_MODULES_H_

#include <map>
#include <vector>
#include <string>
#include <assert.h>
using namespace std;
#include "core/common_types.h"
#include "../include/qb_base.h"
#include "qb_com.h"
#include "core/thirdparty/tinyxml/tinyxml.h"
#pragma comment(lib,"winmm.lib")
//#define LOAD_DLL_FROM_XML

#ifdef _UNICODE
typedef wstring tstring;
#else
typedef string tstring;
#endif // _UNICODE

namespace qb
{
	struct ComObjItem
	{
		IID riid;
		void* ppv;
	};
	struct IIDPred
	{
		bool operator()(const IID &x,const IID &y) const
		{
			return memcmp(&x,&y,sizeof(IID)) < 0;
		}
	};
	typedef map<IID,ComObjItem,IIDPred> ComObjs;
	//-----------------------------------------------------------------------
	struct ComItem 
	{
#ifdef LOAD_DLL_FROM_XML
		ComItem()
		{
			com = NULL;
		}
#endif
		tstring name;
		CLSID clsid;
		QbCom* com;
		ComObjs objs;
	};
	struct CLSIDPred
	{
		bool operator()(const CLSID &x,const CLSID &y) const
		{
			return memcmp(&x,&y,sizeof(CLSID)) < 0;
		}
	};
	typedef map<CLSID,ComItem,CLSIDPred> Coms;
	//-----------------------------------------------------------------------
#ifdef LOAD_DLL_FROM_XML
	typedef map<CLSID,tstring,CLSIDPred> Modules;
#endif
	class QbModules
	{
#ifndef LOAD_DLL_FROM_XML
		enum {kMaxNumberCom = 22};
#endif
	public:
		QbModules();

		virtual ~QbModules();

		virtual int32_t LoadResource(const char* exepath);

		virtual int32_t UnloadResource();

		virtual int32_t QueryInterface(REFCLSID rclsid,REFIID riid,void** ppv);

	private:
		Coms					m_coms;
#ifdef LOAD_DLL_FROM_XML
		Modules					m_modules;
#else
		static ComItem			m_comDatabase[kMaxNumberCom];
#endif
	};
}  // namespace qb

#endif // _PR_MODULES_H_
